//
//  XJGoodsDetailTitleCollectionViewCell.m
//  XinJiangMall
//
//  Created by Tzyang on 2018/4/11.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJGoodsDetailTitleCollectionViewCell.h"

@interface XJGoodsDetailTitleCollectionViewCell ()

@property (nonatomic, strong) UILabel * xjgdTitleLab;//商品名称
@property (nonatomic, strong) UILabel * xjgdPriceLab;//价格
@property (nonatomic, strong) UILabel * xjgdDiscardLab;//弃用价格
@property (nonatomic, strong) UILabel * xjgdPayNumLab;//付款人数

@end

@implementation XJGoodsDetailTitleCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = WHITE_COLOR;

        [self setupSubviews];
    }
    return self;
}

- (UILabel *)xjgdTitleLab{
    if (!_xjgdTitleLab) {
        UILabel * xjgdTitleLab = [UILabel new];
        self.xjgdTitleLab = xjgdTitleLab;
        [self addSubview:xjgdTitleLab];
    }
    return _xjgdTitleLab;
}

- (UILabel *)xjgdPriceLab{
    if (!_xjgdPriceLab) {
        UILabel * xjgdPriceLab = [UILabel new];
        self.xjgdPriceLab = xjgdPriceLab;
        [self addSubview:xjgdPriceLab];
    }
    return _xjgdPriceLab;
}

- (UILabel *)xjgdDiscardLab{
    
    if (!_xjgdDiscardLab) {
        UILabel * xjgdDiscardLab = [UILabel new];
        self.xjgdDiscardLab = xjgdDiscardLab;
        [self addSubview:xjgdDiscardLab];
    }
    return _xjgdDiscardLab;
}

- (UILabel *)xjgdPayNumLab{
    if (!_xjgdPayNumLab) {
        UILabel * xjgdPayNumLab = [UILabel new];
        self.xjgdPayNumLab = xjgdPayNumLab;
        [self addSubview:xjgdPayNumLab];
    }
    return _xjgdPayNumLab;
}

- (void)setupSubviews{
    
    UIView * xjgdLine = [[UIView alloc]initWithFrame:CGRectMake(ADAPTWidth(10), self.frame.size.height-0.5, KWidth - 2*ADAPTWidth(10) , 0.5)];
    xjgdLine.backgroundColor = XJCOLOR_RGB(221, 221, 221);
    [self addSubview:xjgdLine];
    
    //名称
    self.xjgdTitleLab.font = XJFONTSET_M(16);
    self.xjgdTitleLab.textColor = XJCOLOR_RGB(17, 17, 17);
    self.xjgdTitleLab.numberOfLines = 2;
    self.xjgdTitleLab.text = @"Danielwellington2018春季新款女纯色长袖薄款上衣修身显瘦初春性感毛衣";
    self.xjgdTitleLab.sd_layout
    .leftSpaceToView(self,ADAPTWidth(12))
    .topSpaceToView(self, ADAPTHeight(12))
    .rightSpaceToView(self, ADAPTWidth(12))
    .heightIs(50);
    //价格
    self.xjgdPriceLab.font = XJFONTSET_M(18);
    self.xjgdPriceLab.textColor = XJCOLOR_RGB(244, 67, 54);
    self.xjgdPriceLab.text = @"￥799.00";
    CGFloat xjgdPriceLabW = [UILabel labelWithLabel:self.xjgdPriceLab
                                  getWidthWithTitle:self.xjgdPriceLab.text
                                               font:self.xjgdPriceLab.font];
    CGFloat xjgdPriceLabH = [UILabel labelWithLabel:self.xjgdPriceLab
                                   getHeightByWidth:xjgdPriceLabW
                                              title:self.xjgdPriceLab.text
                                               font:self.xjgdPriceLab.font];
    self.xjgdPriceLab.sd_layout
    .leftSpaceToView(self, ADAPTWidth(10))
    .topSpaceToView(self.xjgdTitleLab, ADAPTHeight(5))
    .widthIs(xjgdPriceLabW)
    .heightIs(xjgdPriceLabH);
    
    //弃用价格
    self.xjgdDiscardLab.font = XJFONTSET_R(12);
    self.xjgdDiscardLab.textColor = XJCOLOR_RGB(121, 130, 133);
    NSString * priceString = @"¥1299.00";
    CGFloat xjgdDiscardLabW = [UILabel labelWithLabel:self.xjgdDiscardLab
                                       getWidthWithTitle:priceString
                                                    font:self.xjgdDiscardLab.font];
    
    CGFloat xjgdDiscardH = [UILabel labelWithLabel:self.xjgdDiscardLab
                                        getHeightByWidth:xjgdDiscardLabW
                                                   title:priceString
                                                    font:self.xjgdDiscardLab.font];
    self.xjgdDiscardLab.sd_layout
    .leftSpaceToView(self.xjgdPriceLab,ADAPTWidth(5))
    .centerYEqualToView(self.xjgdPriceLab)
    .widthIs(xjgdDiscardLabW)
    .heightIs(xjgdDiscardH);
    
    //添加中划线
    NSDictionary *attribtDic = @{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString:priceString attributes:attribtDic];
    // 赋值
    self.xjgdDiscardLab.attributedText = attribtStr;
    
    //付款人数
    self.xjgdPayNumLab.font = XJFONTSET_R(12);
    self.xjgdPayNumLab.textColor = XJCOLOR_RGB(121, 130, 133);
    self.xjgdPayNumLab.text = @"266人付款";
    CGFloat xjgdPayNumLabW = [UILabel labelWithLabel:self.xjgdPayNumLab
                                   getWidthWithTitle:self.xjgdPayNumLab.text
                                                font:self.xjgdPayNumLab.font];
    CGFloat xjgdPayNumLabH = [UILabel labelWithLabel:self.xjgdPayNumLab
                                   getHeightByWidth:xjgdPayNumLabW
                                              title:self.xjgdPayNumLab.text
                                               font:self.xjgdPayNumLab.font];
    self.xjgdPayNumLab.sd_layout
    .rightSpaceToView(self, ADAPTWidth(20))
    .centerYEqualToView(self.xjgdPriceLab)
    .widthIs(xjgdPayNumLabW)
    .heightIs(xjgdPayNumLabH);
}



@end
